﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace Technoera.Common.Interop
{
    public class SizedDataTypeDefinition : DataTypeDefinition
    {
        public SizedDataTypeDefinition(SizedDbType dbType, int size) : base(GetDbType(dbType))
        {
            Size = size;
        }

        public int Size { get; set; }

        private static Dictionary<SizedDbType, DbType> _conversionDictionary;
        private static Dictionary<SizedDbType, DbType> GetConversionDictionary()
        {
            if (_conversionDictionary == null)
            {
                _conversionDictionary = new Dictionary<SizedDbType, DbType>();
                _conversionDictionary.Add(SizedDbType.UnicodeVarChar, DbType.String);
            }
            return _conversionDictionary;
        }

        private static DbType GetDbType(SizedDbType dbType)
        {
            return GetConversionDictionary()[dbType];
        }

        //private static SqlDbType GetSqlDbType(SizedDbType dbType)
        //{
        //    SqlDbType result = (SqlDbType)dbType;
        //    if (!result.ToString().Equals(dbType.ToString()))
        //    {
        //        throw new ApplicationException("Framework version error: System.Data.SqlDbType has different values from .NET 2.0 version.");
        //    }
        //    return result;
        //}

    }
}
